namesList = ['xiaoWang', 'xiaoZhang', 'xiaoHua']
print(namesList[0])
print(namesList[1])
print(namesList[2])

"""
判断
"""
print('TOM' in namesList)
print('xiaoZhang' in namesList)
print('TOM' not in namesList)
# 查找输入用户名是否已存在
new_name = input("请输入您的邮箱账号名:")
if new_name in namesList:
    print("用户名已存在")
else:
    print("可以注册")

"""
增加数据：
append()
extend()
insert()
"""
namesList.append(new_name)
print(namesList)  # ['xiaoWang', 'xiaoZhang', 'xiaoHua', '123']
namesList.extend(new_name)
print(namesList)  # ['xiaoWang', 'xiaoZhang', 'xiaoHua', '123', '1', '2', '3']
namesList.insert(2, new_name)
print(namesList)  # ['xiaoWang', 'xiaoZhang', '123', 'xiaoHua', '123', '1', '2', '3']

"""
删除数据
del
pop()
remove()
clear()
"""
# del namesList
del namesList[0]
print(namesList)
print(namesList.pop())
print(namesList.pop(2))

"""
修改操作
"""
num_list = ['xiaoWang', 'xiaoZhang', 'xiaoHua']
num_list[0] = "111"
print(num_list)

list1 = [1, 3, 2, 5, 4, 6]
# 逆序排列
list1.reverse()
print(list1)
# 排序 -- 升序(默认)
list1.sort()
list1.sort(reverse=False)
print(list1)

"""
复制操作
"""
num_list = ['xiaoWang', 'xiaoZhang', 'xiaoHua']
list1 = num_list.copy()
print(list1)

"""
遍历：while, for
"""
i = 0
while i < len(list1):
    print(list1[i])
    i += 1

for i in list1:
    print(i)

"""
列表嵌套
"""

namesList = [['小明', '小红', '小绿'], ['Tom', 'lily', 'Lady'], ['xiaoming', 'xiaohong', 'xiaolv']]
print(namesList[0][0])
print(namesList[2][2])

"""
需求：有三个办公室,有八个老师,将八个老师随机分配到办公室中
"""
import random

teachers = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
offices = [[], [], []]
for name in teachers:
    offices[random.randint(0, 2)].append(name)
print(offices)

i = 1
for office in offices:
    print(f'办公室{i}人数为{len(office)}')
    i += 1
    for name in office:
        print(f'老师名字为{name}')